package com.qq.mobilemanager.activity;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.qq.mobilesafe.R;
import com.qq.mobilesafe.fragment.LockFragment;
import com.qq.mobilesafe.fragment.UnLockFragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.TextView;

public class AppLockActivity extends FragmentActivity implements
		OnClickListener {

	@ViewInject(R.id.tv_lock)
	private TextView tv_lock;

	@ViewInject(R.id.tv_unlock)
	private TextView tv_unlock;

	@ViewInject(R.id.fl_content)
	private FrameLayout fl_content;

	private FragmentManager fragmentManager;
	private UnLockFragment unLockFragment;
	private LockFragment lockFragment;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initView();
	}

	private void initView() {
		setContentView(R.layout.activity_app_lock);
		ViewUtils.inject(this);
		
		tv_lock.setOnClickListener(this);
		tv_unlock.setOnClickListener(this);
		//获取到fragment 的管理者，兼容低版本
		fragmentManager = getSupportFragmentManager();
		// 开启一个事务
		FragmentTransaction transaction = fragmentManager.beginTransaction();
		unLockFragment = new UnLockFragment();
		lockFragment = new LockFragment();
		// 设置默认显示的fragment，替换当前的页面
		transaction.replace(R.id.fl_content, unLockFragment).commit();

	}

	@Override
	public void onClick(View v) {

		FragmentTransaction transaction = fragmentManager.beginTransaction();

		switch (v.getId()) {
		case R.id.tv_lock:
			tv_lock.setBackgroundResource(R.drawable.tab_left_default);
			tv_unlock.setBackgroundResource(R.drawable.tab_right_pressed);
			transaction.replace(R.id.fl_content, unLockFragment);
			break;
		case R.id.tv_unlock:
			tv_lock.setBackgroundResource(R.drawable.tab_left_pressed);
			tv_unlock.setBackgroundResource(R.drawable.tab_right_default);
			transaction.replace(R.id.fl_content, lockFragment);
			break;

		}
		transaction.commit();
	}

}
